//
//  Common.m
//  NewsReader
//
//  Created by Xiangxiang on 16/4/18.
//  Copyright © 2016年 GaoSir_. All rights reserved.
//

#import "Common.h"
@implementation NSObject (PerformBlockAfterDelay)
- (void)performDelay:(NSTimeInterval)delay block:(void (^)(void))block{
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay *NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), block);
}
@end

@implementation NSNotificationCenter (NotificationBlock)
+ (void)postNotification:(NSString *)name userInfo:(NSDictionary *)userInfo{
    [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:userInfo];
}
+ (void)addObserver:(NSString *)name block:(void (^)(void))block{
    [[NSNotificationCenter defaultCenter] addObserverForName:name object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        block();
        [[NSNotificationCenter defaultCenter] removeObserver:self name:name object:nil];
    }];
}
@end

@implementation Common
+ (id)shared{
    static dispatch_once_t onceToken;
    static Common * sSharedInstance;
    dispatch_once(&onceToken, ^{
        sSharedInstance = [[Common alloc] init];
    });
    return sSharedInstance;
}

+ (BOOL)isIpad{
    if (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2) {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            return YES;
        }else{
            return NO;
        }
    }else{
        return NO;
    }
}


@end
